package com.zr.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zr.dao.Zlroledao;
import com.zr.model.Role;
import com.zr.model.User;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Zlroleimpl implements Zlroledao{
	
	  
	  public JSONArray allrole(){
		  
		  JSONArray jsons = new JSONArray();
		   Connection con = JDBCUtil.getConnection();
		  
		try {
			
		     StringBuffer st = new StringBuffer();
		     st.append("select rid , rname  ");
		     st.append("from e_role  ");
		    
		     PreparedStatement pst = con.prepareStatement(st.toString());
		    
		     ResultSet rs = pst.executeQuery();
		     
		     while(rs.next())
		     {   
		    	 JSONObject j = new JSONObject();
		    	 j.put("id",rs.getInt("rid"));
		    	 j.put("text",rs.getString("rname"));
		    	 jsons.add(j);
		     }
		    	 
		     
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		  return jsons;
	  }
}
